package com.zhaodui.pos.controller;
import com.zhaodui.dhcar.entity.FxjDhCarInfoEntity;
import com.zhaodui.dhcar.entity.FxjDhImpEntity;
import com.zhaodui.order.entity.FxjOrderAttaEntity;
import com.zhaodui.pl.entity.FxjPlReplanEntity;
import com.zhaodui.pos.entity.PosDetailEntity;
import com.zhaodui.pos.entity.PosXjtaskEntity;
import com.zhaodui.pos.page.PosXjtaskPage;
import com.zhaodui.pos.service.PosDetailServiceI;

import java.io.File;
import java.io.FileOutputStream;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhaodui.restapi.entity.FileMeta;
import com.zhaodui.util.fxjUtil;
import org.jeecgframework.core.util.*;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.service.SystemService;

import java.io.OutputStream;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;

import java.io.IOException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.jeecgframework.core.beanvalidator.BeanValidators;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.net.URI;
import org.springframework.http.MediaType;
import org.springframework.web.util.UriComponentsBuilder;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import static com.xiaoleilu.hutool.date.DateTime.now;

/**   
 * @Title: Controller  
 * @Description: POS主数据
 * @author onlineGenerator
 * @date 2019-04-06 07:03:10
 * @version V1.0   
 *
 */
@Api(value="PosDetail",description="POS主数据",tags="posDetailController")
@Controller
@RequestMapping("/posDetailController")
public class PosDetailController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(PosDetailController.class);
	@Autowired
	private UserService userService;
	@Autowired
	private PosDetailServiceI posDetailService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private Validator validator;
	


	/**
	 * POS主数据列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "list")
	public ModelAndView list(HttpServletRequest request) {
		return new ModelAndView("com/zhaodui/pos/posDetailList");
	}

	/**
	 * easyui AJAX请求数据
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param user
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(PosDetailEntity posDetail,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(PosDetailEntity.class, dataGrid);
		//查询条件组装器
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, posDetail, request.getParameterMap());
		try{
		//自定义追加查询条件
		
		}catch (Exception e) {
			throw new BusinessException(e.getMessage());
		}
		cq.add();
		this.posDetailService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 删除POS主数据
	 * 
	 * @return
	 */
	@RequestMapping(params = "doDel")
	@ResponseBody
	public AjaxJson doDel(PosDetailEntity posDetail, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		posDetail = systemService.getEntity(PosDetailEntity.class, posDetail.getId());
		message = "POS主数据删除成功";
		try{
			posDetailService.delete(posDetail);
			systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "POS主数据删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 批量删除POS主数据
	 * 
	 * @return
	 */
	 @RequestMapping(params = "doBatchDel")
	@ResponseBody
	public AjaxJson doBatchDel(String ids,HttpServletRequest request){
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "POS主数据删除成功";
		try{
			for(String id:ids.split(",")){
				PosDetailEntity posDetail = systemService.getEntity(PosDetailEntity.class, 
				id
				);
				posDetailService.delete(posDetail);
				systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
			}
		}catch(Exception e){
			e.printStackTrace();
			message = "POS主数据删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}


	/**
	 * 添加POS主数据
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(params = "doAdd")
	@ResponseBody
	public AjaxJson doAdd(PosDetailEntity posDetail, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "POS主数据添加成功";
		try{
			posDetailService.save(posDetail);
		try{
			if(StringUtil.isNotEmpty(posDetail.getPosNo())){
				TSUser users = systemService.findUniqueByProperty(TSUser.class, "userName",posDetail.getPosNo());
				if (users == null) {
					TSUser user = new TSUser();
					user.setUserName(posDetail.getPosNo());
					user.setRealName(posDetail.getPosName());
					String roleid = "POSKH";
					String orgid = "A03";
					user.setPassword(PasswordUtil.encrypt(user.getUserName(), oConvertUtils.getString("123456"), PasswordUtil.getStaticSalt()));
					user.setStatus(Globals.User_Normal);
					user.setDeleteFlag(Globals.Delete_Normal);
					//默认添加为系统用户
					user.setUserType(Globals.USER_TYPE_SYSTEM);
					this.userService.saveOrUpdate(user, orgid.split(","), roleid.split(","));
				}
			}
		}catch (Exception e){

		}



			systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "POS主数据添加失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 更新POS主数据
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(params = "doUpdate")
	@ResponseBody
	public AjaxJson doUpdate(PosDetailEntity posDetail, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "POS主数据更新成功";
		PosDetailEntity t = posDetailService.get(PosDetailEntity.class, posDetail.getId());
		try {
			MyBeanUtils.copyBeanNotNull2Bean(posDetail, t);
			posDetailService.saveOrUpdate(t);
			systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
		} catch (Exception e) {
			e.printStackTrace();
			message = "POS主数据更新失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	

	/**
	 * POS主数据新增页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goAdd")
	public ModelAndView goAdd(PosDetailEntity posDetail, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(posDetail.getId())) {
			posDetail = posDetailService.getEntity(PosDetailEntity.class, posDetail.getId());
			req.setAttribute("posDetail", posDetail);
		}
		return new ModelAndView("com/zhaodui/pos/posDetail-add");
	}
	/**
	 * POS主数据编辑页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goUpdate")
	public ModelAndView goUpdate(PosDetailEntity posDetail, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(posDetail.getId())) {
			posDetail = posDetailService.getEntity(PosDetailEntity.class, posDetail.getId());
			req.setAttribute("posDetail", posDetail);
		}
		return new ModelAndView("com/zhaodui/pos/posDetail-update");
	}
	
	/**
	 * 导入功能跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "upload")
	public ModelAndView upload(HttpServletRequest req) {
		req.setAttribute("controller_name","posDetailController");
		return new ModelAndView("common/upload/pub_excel_upload");
	}
	
	/**
	 * 导出excel
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXls")
	public String exportXls(PosDetailEntity posDetail,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
		CriteriaQuery cq = new CriteriaQuery(PosDetailEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, posDetail, request.getParameterMap());
		List<PosDetailEntity> posDetails = this.posDetailService.getListByCriteriaQuery(cq,false);
		modelMap.put(NormalExcelConstants.FILE_NAME,"POS主数据");
		modelMap.put(NormalExcelConstants.CLASS,PosDetailEntity.class);
		modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("POS主数据列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
			"导出信息"));
		modelMap.put(NormalExcelConstants.DATA_LIST,posDetails);
		return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	/**
	 * 导出excel 使模板
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsByT")
	public String exportXlsByT(PosDetailEntity posDetail,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
    	modelMap.put(NormalExcelConstants.FILE_NAME,"POS主数据");
    	modelMap.put(NormalExcelConstants.CLASS,PosDetailEntity.class);
    	modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("POS主数据列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
    	"导出信息"));
    	modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
    	return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(params = "importExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				List<PosDetailEntity> listPosDetailEntitys = ExcelImportUtil.importExcel(file.getInputStream(),PosDetailEntity.class,params);
				for (PosDetailEntity posDetail : listPosDetailEntitys) {
					posDetailService.save(posDetail);

					try{
						if(StringUtil.isNotEmpty(posDetail.getPosNo())){
							TSUser users = systemService.findUniqueByProperty(TSUser.class, "userName",posDetail.getPosNo());
							if (users == null) {
								TSUser user = new TSUser();
								user.setUserName(posDetail.getPosNo());
								user.setRealName(posDetail.getPosName());
								String roleid = "POSKH";
								String orgid = "A03";
								user.setPassword(PasswordUtil.encrypt(user.getUserName(), oConvertUtils.getString("123456"), PasswordUtil.getStaticSalt()));
								user.setStatus(Globals.User_Normal);
								user.setDeleteFlag(Globals.Delete_Normal);
								//默认添加为系统用户
								user.setUserType(Globals.USER_TYPE_SYSTEM);
								this.userService.saveOrUpdate(user, orgid.split(","), roleid.split(","));
							}
						}
					}catch (Exception e){

					}

				}
				j.setMsg("文件导入成功！");
			} catch (Exception e) {
				j.setMsg("文件导入失败！");
				logger.error(ExceptionUtil.getExceptionMessage(e));
			}finally{
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return j;
	}


	@RequestMapping(value="/list/{username}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value="POS主数据列表信息",produces="application/json",httpMethod="GET")
	public ResponseMessage<List<PosDetailEntity>> list(@PathVariable("username") String username, @RequestParam int pageNumber, @RequestParam int pageSize, HttpServletRequest request) {
		if(pageSize > Globals.MAX_PAGESIZE){
			return Result.error("每页请求不能超过" + Globals.MAX_PAGESIZE + "条");
		}
		CriteriaQuery query = new CriteriaQuery(PosDetailEntity.class);
		TSUser task = fxjUtil.getsysorgcode(username);
		String orgcode = "";
		if (task != null) {
			orgcode = task.getCurrentDepart().getSysOrgCode();
			query.like("sysOrgCode", orgcode + "%");

		}
        if(StringUtil.isNotEmpty(request.getParameter("bpmStatus"))){
            query.eq("bpmStatus",request.getParameter("bpmStatus"));
        }
        if(StringUtil.isNotEmpty(request.getParameter("posNo"))){
            query.eq("posNo",request.getParameter("posNo"));
        }
        if(StringUtil.isNotEmpty(request.getParameter("posName"))){
            query.eq("posName",request.getParameter("posName"));
        }
		query.add();
		List<PosDetailEntity> listsize = this.posDetailService.getListByCriteriaQuery(query,false);
		query.setCurPage(pageNumber<=0?1:pageNumber);
		query.setPageSize(pageSize<1?1:pageSize);
		query.add();
		List<PosDetailEntity> listPosDetails = this.posDetailService.getListByCriteriaQuery(query,true);
		return Result.success(listPosDetails,(long)listsize.size());
	}
	
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value="根据ID获取POS主数据信息",notes="根据ID获取POS主数据信息",httpMethod="GET",produces="application/json")
	public ResponseMessage<?> get(@ApiParam(required=true,name="id",value="ID")@PathVariable("id") String id) {
		PosDetailEntity task = posDetailService.get(PosDetailEntity.class, id);
		if (task == null) {
			try{
				task = posDetailService.findUniqueByProperty(PosDetailEntity.class, "posNo",id);
			}catch (Exception e){
			}
			if(task == null){
				return Result.error("根据ID获取POS主数据信息为空");
			}
		}
		try{
            String imgserver = ResourceUtil.getConfigByName("img.server");
            String imgpath = ResourceUtil.getConfigByName("showAndDownUrl");
            task.setShPic1(imgserver+imgpath+task.getShPic1());
            task.setShPic2(imgserver+imgpath+task.getShPic2());
            task.setShYyzz(imgserver+imgpath+task.getShYyzz());
            task.setShShxy(imgserver+imgpath+task.getShShxy());
            task.setShOtherpic(imgserver+imgpath+task.getShOtherpic());
        }catch (Exception e0){
        }
		return Result.success(task);
	}

	@RequestMapping(value = "/getbyopenid/{openid}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value="根据OPENID获取POS主数据信息",notes="根据ID获取POS主数据信息",httpMethod="GET",produces="application/json")
	public ResponseMessage<?> getbyopenid(@ApiParam(required=true,name="openid",value="openid")@PathVariable("openid") String openid) {
		TSUser tsuser = fxjUtil.getsysorgcode(openid);
		PosDetailEntity task = posDetailService.findUniqueByProperty(PosDetailEntity.class, "posNo",tsuser.getUserName());
		if (task == null) {
			return Result.error("根据ID获取POS主数据信息为空");
		}
		try{
			String imgserver = ResourceUtil.getConfigByName("img.server");
			String imgpath = ResourceUtil.getConfigByName("showAndDownUrl");

			task.setShPic1(imgserver+imgpath+task.getShPic1());
			task.setShPic2(imgserver+imgpath+task.getShPic2());
			task.setShYyzz(imgserver+imgpath+task.getShYyzz());
			task.setShShxy(imgserver+imgpath+task.getShShxy());
			task.setShOtherpic(imgserver+imgpath+task.getShOtherpic());
		}catch (Exception e0){

		}


		return Result.success(task);
	}

	@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@ApiOperation(value="创建POS主数据")
	public ResponseMessage<?> create(@ApiParam(name="POS主数据对象")@RequestBody PosDetailEntity posDetail, UriComponentsBuilder uriBuilder) {
		//调用JSR303 Bean Validator进行校验，如果出错返回含400错误码及json格式的错误信息.
		Set<ConstraintViolation<PosDetailEntity>> failures = validator.validate(posDetail);
		if (!failures.isEmpty()) {
			return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
		}

		//保存
		try{

			posDetailService.save(posDetail);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("POS主数据信息保存失败");
		}
		return Result.success(posDetail);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@ApiOperation(value="更新POS主数据",notes="更新POS主数据")
	public ResponseMessage<?> update(@ApiParam(name="POS主数据对象")@RequestBody PosDetailEntity posDetail) {
		//调用JSR303 Bean Validator进行校验，如果出错返回含400错误码及json格式的错误信息.
		Set<ConstraintViolation<PosDetailEntity>> failures = validator.validate(posDetail);
		if (!failures.isEmpty()) {
			return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
		}

		//保存
		try{
			PosDetailEntity t = posDetailService.get(PosDetailEntity.class, posDetail.getId());
			MyBeanUtils.copyBeanNotNull2Bean(posDetail,t);
			posDetailService.saveOrUpdate(t);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("更新POS主数据信息失败");
		}

		//按Restful约定，返回204状态码, 无内容. 也可以返回200状态码.
		return Result.success("更新POS主数据信息成功");
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	@ResponseStatus(HttpStatus.NO_CONTENT)
	@ApiOperation(value="删除POS主数据")
	public ResponseMessage<?> delete(@ApiParam(name="id",value="ID",required=true)@PathVariable("id") String id) {
		logger.info("delete[{}]" , id);
		// 验证
		if (StringUtils.isEmpty(id)) {
			return Result.error("ID不能为空");
		}
		try {
			posDetailService.deleteEntityById(PosDetailEntity.class, id);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("POS主数据删除失败");
		}

		return Result.success();
	}


	@RequestMapping(value="/uploadexcel", method = RequestMethod.POST)
	@ApiOperation(value="数据上传",notes="数据上传",httpMethod="POST",produces="application/json")
	public @ResponseBody
	LinkedList<FileMeta> upload(MultipartHttpServletRequest request, HttpServletResponse response) {
		String username = request.getParameter("username");

		LinkedList<FileMeta> files = new LinkedList<FileMeta>();
		String showAndDownUrl = ResourceUtil.getConfigByName("showAndDownUrl");
		String imgserver = ResourceUtil.getConfigByName("img.server");
		FileMeta fileMeta = null;
		//1. build an iterator
		Iterator<String> itr =  request.getFileNames();
		MultipartFile mpf = null;
		String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
		//2. get each file
		String savaPath= ResourceUtil.getConfigByName("webUploadpath");
		String  filename = "";
		String  filenameweb = "";
		String ctxPath = "";
		while(itr.hasNext()){

			//2.1 get next MultipartFile
			mpf = request.getFile(itr.next());
			System.out.println(mpf.getOriginalFilename() +" uploaded! "+files.size());

			//2.2 if files > 10 remove the first from the list

			filename = filest + File.separator+mpf.getOriginalFilename();
			filenameweb = filest + "/"+mpf.getOriginalFilename();

			FxjOrderAttaEntity fxjOrderAttaEntity = new FxjOrderAttaEntity();
			fxjOrderAttaEntity.setCreateDate(now());
			fxjOrderAttaEntity.setAttaName(filest+File.separator+mpf.getOriginalFilename());
			fxjOrderAttaEntity.setAttaSize(mpf.getSize()/1024+" KB");
			fxjOrderAttaEntity.setBpmStatus("1");
			fxjOrderAttaEntity.setAttaUrl(imgserver+showAndDownUrl+filenameweb);
			//2.3 create new fileMeta
			fileMeta = new FileMeta();
			fileMeta.setFileName(mpf.getOriginalFilename());
			fileMeta.setFileSize(mpf.getSize()/1024+" KB");
			fileMeta.setFileType(mpf.getContentType());
			fileMeta.setFileUrl(fxjOrderAttaEntity.getAttaUrl());
			try {
				fileMeta.setBytes(mpf.getBytes());
				// copy file to local disk (make sure the path "e.g. D:/temp/files" exists)
				ctxPath=savaPath;

				File file = new File(ctxPath+File.separator+filest);
				if (!file.exists()) {
					file.mkdirs();// 创建文件根目录
				}
				FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream(ctxPath+File.separator+filename));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//2.4 add to files
			files.add(fileMeta);



		}
		ImportParams params = new ImportParams();
		params.setTitleRows(0);
		params.setHeadRows(1);
		params.setNeedSave(false);
		try {
			System.out.print("111***"+now());
//			InputStream input = null;
//			input = new File(ctxPath+File.separator+filename);
			List<PosDetailEntity> listFxjDhCarInfoEntitys = ExcelImportUtil.importExcel(new File(ctxPath+File.separator+filename),PosDetailEntity.class,params);
			System.out.print("22222***"+now());
			for (PosDetailEntity fxjDhCarInfo : listFxjDhCarInfoEntitys) {
				fxjDhCarInfo.setCreateBy(username);
				fxjDhCarInfo.setCreateDate(now());
				systemService.save(fxjDhCarInfo);
			}
		}catch (Exception e){

		}
		return files;
	}

}
